package com.wehotel.common.model;

import com.wehotel.common.exception.BizException;
import io.swagger.annotations.ApiModelProperty;


public class R {

    public static final R SUCC=new R(0,"成功");
    public static final R STATE_ERROR=new R(-2,"状态异常");
    public static final R PARAM_ERROR =new R(-3,"参数异常");
    public static final R UNKNOW=new R(-4,"未知异常");


    @ApiModelProperty(value = "编码，0为成功")
    private int code;
    @ApiModelProperty(value = "编码，描述")
    private String msg;

    public R(){}
    public R(int c){
        this.code=c;
    }
    public R(int c,String m){
        this.code=c;
        this.msg=m;
    }


    public static<T extends R> T successOf(Class<T> c){
        try {
            T t = (T)c.newInstance();
            t.setCode(SUCC.getCode());
            t.setMsg(SUCC.getMsg());
            return t;
        } catch (Exception e) {
            throw new BizException(-4, "系统获取成功响应实例失败，type=" + c.getName());
        }
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

}
